package com.legolas.demo.service;

import com.legolas.demo.domain.Resource;
import com.legolas.shiroconfig.PasswordHelper;
import com.legolas.demo.domain.Role;
import com.legolas.demo.domain.User;
import com.legolas.demo.dao.UserDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserService {

    private Logger logger = LoggerFactory.getLogger(UserService.class);

    @Autowired
    private UserDao userDao;


    public void add(User user){
        user.setPassword(PasswordHelper.md5Pwd(user.getPassword(),user.getUsername()));
        userDao.addUser(user);
    }

    public void addUserRole(int uid, int roleId) {
        userDao.addUserRole(uid, roleId);
    }

    public void updateUser(User user){
        userDao.updateUser(user);
    }

    public User queryUserByName(String username) {
        return userDao.queryUserByName(username);
    }

    public List<Resource> queryResourceByUserId(int uid) {
        return userDao.queryResourceByUserId(uid);
    }

    public List<Role> queryRoleByUserId(int uid) {
        return userDao.queryRoleByUserId(uid);
    }


    public List<User> queryAllUser() {
        return userDao.queryAllUser();
    }

    public User queryUserById(int id){
       return userDao.queryUserById(id);
    }

    public void deleteUser(int id){
        userDao.deleteUser(id);
    }

    public void deleteUserRoleByUserId(int uid) {
        userDao.deleteUserRoleByUserId(uid);
    }

}
